home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 911 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. From: kanze@gabi-soft.fr (J. Kanze)
  2. Message-ID: <KANZE.96Mar29115450@gabi.gabi-soft.fr>
  3. X-Original-Date: 29 Mar 1996 10:54:50 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 30 Mar 96 05:38:06 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Enumerated type converted to pointer? Legal?
  9. Organization: GABI Software, Sarl.
  10. References: <4hobji$mco@netlab.cs.rpi.edu> <KANZE.96Mar22115626@gabi.gabi-soft.fr>
  11.     <315a9640.1061096@news.ultranet.com>
  12. In-Reply-To: phalpern@truffle.ultranet.com's message of 28 Mar 96 13:59:51 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMVzIzOEDnX0m9pzZAQGgzAGAiqn0Bd2oq1hbCznxH2C9BZiucYUkG7vL
  15.     r74Hyxcc1N6qqjAaqlwk/s3fy8qHNyC+
  16.     =2Sok
  17.  
  18. In article <315a9640.1061096@news.ultranet.com>
  19. phalpern@truffle.ultranet.com (Pablo Halpern) writes:
  20.  
  21. |> kanze@gabi-soft.fr (J. Kanze) wrote:
  22.  
  23. |> >The error may be historically conditioned.  As I interpret the C
  24. |> >standard, an enumerated constant has type int, and a constant integral
  25. |> >expression which evalutates to 0 is a null pointer.  Even in the ARM,
  26. |> >however, ``An enumeration is a distinct integral type.''
  27.  
  28. |> That begs the question, however, whether being an integral type with
  29. |> constant value zero is sufficient to allow assignment to a pointer.
  30.  
  31. |> Is this legal? I believe all of the above is legal, though IMO it
  32. |> shouldn't be (see below)
  33.  
  34. |>     enum ptrNil { nil3 };
  35. |>     void *p = nil3;
  36.  
  37. |> You are claiming that this is not legal because nil3 is of type ptrNil
  38. |> which is not compatable with the type of p. However, I fail to see how
  39. |> nil3 is different from nil1 and nil2 in this respect. All are `integral'
  40. |> types with value zero.
  41.  
  42. Before going any farther, several people have already pointed out my
  43. mistake to me in private email.  Basically, I missed the fact that when
  44. enum's were made full types, the definition of integral constant was
  45. also extended to include them.  So the above is legal, and nil3 is a
  46. legal null pointer.  (In C, it was definitly legal, because the type of
  47. nil3 was expressedly int.  I mistakenly supposed that because C++
  48. changed this type, it had also rendered the above illegal.)
  49.  
  50. I, for one, wouldn't object if the definition of a null pointer were
  51. further restricted to limit it to only {int, unsigned int, long,
  52. unsigned long}.
  53. -- 
  54. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  55. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  56. Conseils en informatique industrielle --
  57.                             -- Beratung in industrieller Datenverarbeitung
  58. ---
  59. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  60. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  61. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  62. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  63. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  64.